Index Pairs of a String
Question
Given a string, find all pairs of indices in the string such that the substring with the two indices as boundaries is a palindrome.
Example 1
Input: text = "ababa"
Output: [[0,1], [0,3], [2,3], [2,4]]
Solution
- ▭
- ▯
all//Index Pairs of a String.py
def index_pair(string):
result = []
for i in range(len(string)):
for j in range(i + 1, len(string)):
result.append((i, j))
return result
# Driver Code
string = 'geeksforgeeks'
print(index_pair(string))
all//Index Pairs of a String.py
def index_pair(string):
result = []
for i in range(len(string)):
for j in range(i + 1, len(string)):
result.append((i, j))
return result
# Driver Code
string = 'geeksforgeeks'
print(index_pair(string))